{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
.file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
.file-item .info{overflow: hidden;}
.uploader-list{width: 100%; overflow: hidden;}
</style>
<style>
	.layui-upload-list{display: flex;flex-wrap:wrap;}
	.layui-upload-list div{display: inline-block;text-align: center;cursor: pointer;flex-direction: column;display: flex;margin-right: 8px;}
	.layui-upload-list div img{height:100px;}
	.layui-upload-list div video{height:100px;}
	.layui-upload-list div span{display: block;}
	
	#div-slide_show_pic{display:flex;flex-wrap:wrap;}
	.item-img {
		flex-direction: column;
		display: flex;
		margin-right: 18px;
		margin-bottom:17px;width:12%;text-align:center;
	}
	.item-img img{max-width: 100%;}
	.delMultipleImgs4{text-align:center;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加/编辑</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" name="edit" id="edit" method="post" action="edit_article">
                    <input type="hidden" name="id" value="{$article.id??''}">
                    <input type="hidden" name="school_id" value="{$school_id??''}">
                    <input type="hidden" name="type" value="2">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="input-group col-sm-4">
                                <input id="title" type="text" class="form-control" name="title" value="{$article.title??''}">
                            </div>
                        </div>
                       
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">内容形式：</label>
                            <div class="col-sm-6">
                                    <input type="radio" name='content_type' value="0" {if condition="$article['content_type'] eq 0 "}checked{/if}/>文本&nbsp;&nbsp;
                                    <input type="radio" name='content_type' value="1" {if condition="$article['content_type'] eq 1 "}checked{/if}/>PDF
                                
                            </div>
                        </div>
						
                        <div class="hr-line-dashed"></div>
						
                        <div class="form-group pdf_type" {if condition="$article['content_type'] eq 0 "}style="margin-left:-5000px"{/if}>
                            <label class="col-sm-3 control-label">PDF文件：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" id="data_photo" name="file_url" value="{$article['file_url']??''}">
                                <div id="fileList" class="uploader-list" style="float:right"></div>
                                <div id="imgPicker" style="float:left">选择文件</div>
                            </div>
                        </div>
						
                        <div class="form-group pdf_content" {if condition="$article['content_type'] eq 1 "}style="display:none"{/if}>
                            <label class="col-sm-3 control-label " for="myEditor">详情：</label>
                            <div class="input-group col-sm-9">
                                <script src="/static/admin/ueditor/ueditor.config.js" type="text/javascript"></script>
                                <script src="/static/admin/ueditor/ueditor.all.js" type="text/javascript"></script>
                                <textarea name="content" style="width:90%" id="myEditor">{$article.content??''}</textarea>
                                <script type="text/javascript">
                                    var editor = new UE.ui.Editor();
                                    editor.render("myEditor");
                                </script>
                            </div>
                        </div>
					


                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">访问量：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" name="views" id="views" value="1" class="form-control" value="{$article.views??''}">
                            </div>
                        </div>

                       
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">状&nbsp;态：</label>
                            <div class="col-sm-6">
                                <div class="radio i-checks">
                                    <input type="radio" name='status' value="1" {if condition="$article['status'] eq 1 "}checked{/if}/>开启&nbsp;&nbsp;
                                    <input type="radio" name='status' value="0" {if condition="$article['status'] eq 0 "}checked{/if}/>关闭
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit" id="c_s"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
  {include file="public/footer" /}

    <link rel="stylesheet" href="/static/admin/css/layui.css" media="all"/>
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>
<!--<script type="text/javascript" src="/static/admin/js/wangEditor.min.js"></script>-->
<script type="text/javascript" src="/static/admin/js/layui.js"></script>
<script>
	
	$("input[name=content_type]").click(function(){
		var content_type = $(this).val();
		if(content_type == 1){
			$(".pdf_type").css('margin-left','-15px');
			$(".pdf_content").hide();
		}else{
			$(".pdf_type").css('margin-left','-5000px');
			$(".pdf_content").show();
		}
	})
	
	var $list = $('#fileList');
	var uploader = WebUploader.create({

		auto: true,// 选完文件后，是否自动上传。
		swf: '/static/admin/webupload/Uploader.swf',// swf文件路径
		server: "{:url('Upload/upload_oss')}",// 文件接收服务端。
		duplicate :true,// 重复上传图片，true为可重复false为不可重复
		pick: '#imgPicker',// 选择文件的按钮。可选。

		accept: {
			title: 'Images',
			extensions: 'pdf',
			mimeTypes: 'application/pdf'
		},

		'onUploadSuccess': function(file, data, response) {
			$("#data_photo").val(data.data.src);
		}
	});
    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">正在上传...</p>' +
            '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });
</script>	
<script type="text/javascript">

 /*   var E = window.wangEditor;
    var editor = new E('#div1');
    editor.customConfig.uploadFileName = 'file';//要传参数名
    editor.customConfig.showLinkImg = false;
    editor.customConfig.uploadImgServer = "{:url('Upload/uploads')}";
    editor.customConfig.uploadImgHooks = {
        //图片上传并返回结果，自定义插入图片的事件
        customInsert: function (insertImg, result, editor) {
            if (result.status){
                var url = result.url;
                insertImg(url)
            }else{
                alert('上传失败')
            }
        }
    };
    editor.create();*/

layui.use(['upload'], function () {
	var upload = layui.upload;
    
});

    //提交按钮添加点击事件，获取编辑器的内容
    /*$('#c_s').click(function () {
        $('#myEditor').val();
        $('#myEditor').val(editor.txt.html());
    });*/


    $(function(){
        $('#edit').ajaxForm({
            beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
            success: complete, // 这是提交后的方法
            dataType: 'json'
        });

        function checkForm(){
            if( '' == $.trim($('#title').val())){
                layer.msg('标题不能为空', {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
            

     }

        function complete(data){
            if(data.code == 1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                    window.location.href="{:url('school_baogao/index')}?school_id={$school_id}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return false;
            }
        }

    });


    //IOS开关样式配置
   var elem = document.querySelector('.js-switch');
        var switchery = new Switchery(elem, {
            color: '#1AB394'
        });
    var config = {
        '.chosen-select': {},                    
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }



</script>
</body>
</html>
